﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LogicUniversityBiz
{
    public class DepartmentMaintain
    {
        public List<Department> getDepartment()
        {
            LogicUniversityEntities lue = new LogicUniversityEntities();
            var dept = lue.Departments
                 .AsEnumerable()
               .Select(x => x)
               .ToList();
            return dept;
        }

        public int addDepartment(string dept_Code , string dept_Name,string contactName , string tel,string fax , string headName,string collectionPoint,string rep_Name)
    {
        using (LogicUniversityEntities lue = new LogicUniversityEntities())
    {
        Department addDepartment = new Department();
        addDepartment.Collection_Point = collectionPoint;
        addDepartment.Contact_Name = contactName;
        addDepartment.Dept_Code = dept_Code;
        addDepartment.Dept_Name = dept_Name;
        addDepartment.Fax_No = fax;
        addDepartment.Head_Name = headName;
        addDepartment.Rep_Name = rep_Name;
        addDepartment.Tel_No = tel;
        lue.AddToDepartments(addDepartment);
        lue.SaveChanges();
    }
        return 0;
    }
        public int updateDepartment(string dept_Code, string dept_Name, string contactName, string tel, string fax, string headName, string collectionPoint, string rep_Name)
        {
            using (LogicUniversityEntities lue = new LogicUniversityEntities())
            {
                var updateDept = lue.Departments.FirstOrDefault(c => c.Dept_Code == dept_Code);
                {
                    updateDept.Collection_Point = collectionPoint;
                    updateDept.Contact_Name = contactName;
                    updateDept.Dept_Name = dept_Name;
                    updateDept.Fax_No = fax;
                    updateDept.Tel_No = tel;
                    updateDept.Rep_Name = rep_Name;
                    updateDept.Head_Name = headName;
                    lue.SaveChanges();
                }
                return 0;
            }
        }
 }
}


